<?php
	/**
	 * Created by JetBrains PhpStorm.
	 * User: alex
	 * Date: 06.08.13
	 * Time: 14:29
	 * To change this template use File | Settings | File Templates.
	 */
class Controller_Cart extends Controller_Default
{
	function __construct()
	{
		$id = (int) $_GET["id"];
		$this->getProductInfo($id);
	}
	protected
	function getProductInfo()
	{
		$productList = $_COOKIE['cart'];

		$model = new Model_Cart();
		$cartInfo = $model->selectProductInCart($productList);

		$productInCart = explode(",", $productList);
		foreach ($productInCart as $productId)
		{
			foreach ($cartInfo as &$productInfo)
			{
				if ($productInfo['number'] == null) $cartInfo['number'] = 1;
				if ($productInfo["id"] == $productId)
				{
					++$productInfo['number'];
				}
			}
		}
		$view = new View_Cart();
		$view->pageContent = $cartInfo;
		$this->view = $view->view();

		$this->render("cartList.twig");
	}
}
